#include <cstdio>
#include <iostream>
using namespace std;

long long a, b, k;

long long power() {
    long long ans = 1;
    if (b == 0) {
        return ans % k;
    }
    while (b > 0) {
        if (b % 2 == 1) {
            ans = (ans * a) % k;
        }
        b /= 2;
        a = (a * a) % k;
    }
    return ans;
}

int main() {
	cin >> a >> b >> k;
	printf("%lld\n", power());
	return 0;
}